<?php
/*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not 
 *  exist, see <http://www.gnu.org/licenses/>.
 * 
 * $LastChangedDate: 2008-07-10 23:59:20 +0200 (Thu, 10 Jul 2008) $
 * $Rev: 1285 $
 * $Author: gavinspearhead $
 * $Id: viewfiles.php 1285 2008-07-10 21:59:20Z gavinspearhead $
 */

define('ORIGINAL_PAGE', $_SERVER['PHP_SELF']);


$pathvf = realpath(dirname(__FILE__));

require_once "$pathvf/../functions/html_includes.php";

$title = 'URD - ' . $LN['viewfiles_title'];

$message = '';

$hiddenfiles = $hiddenfiles_root = array();

$rprefs = load_config($db);


$is_admin = is_admin($db, $userID);
if ($prefs['hiddenfiles'])
	$hiddenfiles = get_hiddenfiles(get_pref($db, 'hidden_files_list', $userID));
if ($rprefs['global_hiddenfiles'])
	$hiddenfiles_root = get_hiddenfiles(get_config($db, 'global_hidden_files_list'));

$hiddenfiles = array_merge($hiddenfiles, $hiddenfiles_root);

$icons['audio'] = array('mp3', 'wma', 'ogg', 'flac', 'wav', 'ape', 'mpc','au', 'snd', 'oga', 'aiff', 'tak', 'aac', 'mid', 'mp4', 'm4a', 'ra');
$icons['excel'] = array('xls', 'xlsx');
$icons['exe'] = array('exe', 'com', 'bat', 'btm');
$icons['flash'] = array('fla', 'flv', 'swf');
$icons['html'] = array('htm', 'html', 'xhtml', 'tpl');
$icons['iso'] = array('iso', 'img', 'bin', 'nrg', 'cue');
$icons['php'] = array('php');
$icons['source'] = array ('c', 'cc', 'cpp', 'h', 'hpp', 'pas', 'bas', 'pl');
$icons['picture'] = array('jpg', 'jpeg', 'jpe', 'gif', 'bmp', 'png', 'svg', 'tiff', 'jpe', 'psd', 'ani');
$icons['ppt'] = array('ppt', 'pps', 'ppsx', 'pptx');
$icons['script'] = array('js');
$icons['text'] = array('txt', 'text', 'nfo', 'log');
$icons['video'] = array('avi', 'mpg', 'wmv', 'mpeg', 'asf', 'mkv', 'm4v',  'ogv', 'mov', 'vob');
$icons['word'] = array('doc', 'rtf', 'docx');
$icons['zip'] = array('zip', 'rar', 'ace', 'arj', 'lha', '7z', 'gz', 'tgz', 's7z', 'cab', 'ice','lzh', 'bz2', 'tbz2', 'zoo', 'arc', 'jar');
$icons['stylesheet'] = array ('css');
$icons['icon'] = array('ico');
$icons['db'] = array('sql', 'db');
$icons['pdf'] = array('pdf');
$icons['nzb'] = array('nzb');
$icons['par2'] = array('par2', 'par');
$icons['sfv'] = array('sfv', 'sfvmd5', 'csv', 'csv2', 'csv4', 'sha1', 'md5', 'bsdmd5', 'crc'); 
$icons['torrent'] = array('torrent');
$icons['urdd_script'] = array(URDD_SCRIPT_EXT);
$icons['playlist'] = array('m3u', 'pls', 'wpl', 'asx');


function normalise_dir(DatabaseConnection $db, $dir, $username, $is_admin)
{
    $dlpath = get_dlpath($db) ;
    if($dir == '') {
		$cmd = 'show_files'; // if dir is not set we don't want to take any action --> so show files only
        $done_path = realpath($dlpath . DONE_PATH . $username) . '/';
		$dirname = $done_path;
	} else {
        $dirname = realpath($dir) . '/' ;
        if ($dirname == '' || $dirname === FALSE)
            throw new exception($LN['viewfiles_filenotpermitted'], ERR_ACCESS_DENIED);
		if ($is_admin) {
			if (substr($dirname, 0, strlen($dlpath)) != $dlpath) {
				$cmd = 'show_files'; // if dir is not set we don't want to take any action
				$dirname = $dlpath;
			}
        } else {
            $done_path = realpath($dlpath . DONE_PATH . $username . '/');
            $preview_path = realpath($dlpath . PREVIEW_PATH . $username . '/');
            $nzb_path = realpath($dlpath . NZB_PATH . $username . '/');
            $post_path = realpath($dlpath . POST_PATH . $username . '/');
            $scripts_path = realpath($dlpath . SCRIPTS_PATH . $username . '/');

			if (substr($dirname, 0, strlen($done_path)) != $done_path && 
			    substr($dirname, 0, strlen($preview_path)) != $preview_path && 
			    substr($dirname, 0, strlen($scripts_path)) != $scripts_path && 
			    substr($dirname, 0, strlen($nzb_path)) != $nzb_path && 
			    substr($dirname, 0, strlen($post_path)) != $post_path) {
				$cmd = 'show_files'; // if dir is not set we don't want to take any action
				$dirname = $done_path;
			}
		}
	}
	return $dirname;
}


function match_files($filename, $file_list)
{
	foreach ($file_list as $f) {
		if (fnmatch($f, $filename, FNM_CASEFOLD))
			return TRUE;
	}
	return FALSE;
}


function build_skipper(DatabaseConnection $db, $total, $userid, $dir, $offset, $perpage)
{
	assert(is_numeric($total) && is_numeric($total) && is_numeric($offset) && is_numeric($perpage) && $perpage >0);
	$size = SKIPPER_SIZE;
	$totalpages = ceil($total / $perpage);          // Total number of pages.
	$activepage = ceil(($offset+1) / $perpage);     // This is the page we're on. (+1 because 0/100 = page 1)

	$start = max($activepage - floor($size/2), 1);  // We start at 1 unless we're now on page 12, then we show page 2.
	$end = min($start + $size, $totalpages);        // We don't go beyond 'totalpages' ofcourse.
	$start = max($end - $size, 1);                  // Re-check $start, in case the pagenumber is near the end

	$pages = array();
	for ($i = 1; $i <= $totalpages; $i++) {
		$thispage = array();
		$thispage['number'] = $i;
		$pageoffset = ($i - 1) * $perpage;          // For page 1, offset = 0.
		$url = $_SERVER['PHP_SELF'] . "?offset={$pageoffset}&dir=$dir";
		$url = htmlspecialchars($url);
		$thispage['url'] = $pageoffset; // rename to offset
		// distance is the distance from the current page, maximum of 5. Used to colour close pagenumbers:
		$thispage['distance'] = min(abs($activepage - $i),5);
		$pages[] = $thispage;
	}
	return array($pages,$activepage,$totalpages);
}

class a_file {
	public $name;
	public $type;
	public $size;
	public $mtime;
	public $icon;
	public $readable_size;
	public $path;
	public $perms; // as string
	public $perms_num; // as number
	public $group;
	public $owner;
	public $show_delete;

	function __construct($n, $t, $s, $m, $i, $p, $prm, $o, $g ) 
    {
        global $LN;
		$this->name = $n;
		$this->type = $t;
		$this->size = $s;
		if ($s == '')
			$this->readable_size = $s;
		else 
			$this->readable_size = readable_size($s, 1, $LN['byte_short']);
		$this->mtime = $m;
		$this->icon = $i;
		$this->path = $p;
		$this->show_delete = TRUE;
		$this->owner = $o;
		$this->group = $g;
		$this->perms_num = $prm;
		$this->perms = '';
		if ($prm !== NULL)
			$this->perms = perms_to_string($prm);

	}
	function get_show_delete() 
	{ 
		return $this->show_delete;
	}
	function set_show_delete($del) 
	{
		if (is_bool($del))
			$this->show_delete = $del;
	}			

	function get_size()  
	{ 
		if ($this->size === '') 
			return '';
		if ($this->type == 'dir')
			return $this->size;
		else
			return $this->readable_size;
	}

    function get_group()  
    {
        return $this->group;
    }
    function get_owner()  
    {
        return $this->owner;
    }
    function get_name()  
    {
        return $this->name;
    }
    function get_perms()  
    {
        return $this->perms;
    }
    function get_type()  
    {
        return $this->type;
    }
	function get_mtime()  
	{ 
		return ($this->mtime == '') ? '': date ('d M Y H:i', $this->mtime);
	}
    function get_icon()  
    {
        return $this->icon;
    }
	function get_icon_ln() 
	{
		global $LN;
		switch($this->icon) {
			case 'audio':	return $LN['viewfiles_type_audio']; break;
			case 'excel':	return $LN['viewfiles_type_excel']; break;
			case 'exe':	    return $LN['viewfiles_type_exe']; break;
			case 'flash':	return $LN['viewfiles_type_flash']; break;
			case 'html':	return $LN['viewfiles_type_html']; break;
			case 'iso':	return $LN['viewfiles_type_iso']; break;
			case 'php':	return $LN['viewfiles_type_php']; break;
			case 'source':	return $LN['viewfiles_type_source']; break;
			case 'picture':	return $LN['viewfiles_type_picture']; break;
			case 'ppt':	return $LN['viewfiles_type_ppt']; break;
			case 'script':	return $LN['viewfiles_type_script']; break;
			case 'text':	return $LN['viewfiles_type_text']; break;
			case 'video':	return $LN['viewfiles_type_video']; break;
			case 'word':	return $LN['viewfiles_type_word']; break;
			case 'zip':	return $LN['viewfiles_type_zip']; break;
			case 'stylesheet': return $LN['viewfiles_type_stylesheet']; break;
			case 'icon':	return $LN['viewfiles_type_icon']; break;
			case 'db':	return $LN['viewfiles_type_db']; break;
			case 'folder':	return $LN['viewfiles_type_folder']; break;
			case 'file':	return $LN['viewfiles_type_file']; break;
			case 'pdf':	return $LN['viewfiles_type_pdf']; break;
			case 'nzb':	return $LN['viewfiles_type_nzb']; break;
			case 'par2':	return $LN['viewfiles_type_par2']; break;
			case 'sfv':	return $LN['viewfiles_type_sfv']; break;
			case 'playlist':return $LN['viewfiles_type_playlist']; break;
			case 'torrent': return $LN['viewfiles_type_torrent']; break;
			case 'urdd_script': return $LN['viewfiles_type_urdd_sh']; break;
			default:	return '?' . $this->icon . '?';
		}
	}
} // a_file

class file_list {
	public $files; // array
	private $dir; // sort direction
	public $total;
	private $path;
	function __construct() 
	{
		$this->total = 0;
		$this->files = array();
		$this->dir = 1;
	}
	protected function add_file($path, $file_name, $show_delete=TRUE)
	{	
		assert(is_bool($show_delete));
        global $icons;
		$path_filename = $path.$file_name;
		$perms = fileperms($path_filename);
		$owner = fileowner($path_filename);

		$owner = posix_getgrgid($owner);
		$owner = $owner['name'];
		$group = filegroup($path_filename);
		$group = posix_getgrgid($group);
		$group = $group['name'];
		if (is_dir($path_filename)) {
			$glob_path = preg_quote($path_filename);
			$filetype = 'dir';
			$icon = 'folder';
			$size = count(glob($glob_path . '/*', GLOB_NOSORT)) ;
		} else {
			$type = explode('.', $file_name);
			$ext = strtolower($type[(sizeof($type) - 1)]);
			$filetype = 'unknown'; 
			$icon = 'file';
			foreach($icons as $iconName => $iconRange) {
				if(in_array($ext, $iconRange)) {
					$icon = $iconName;
					$filetype = $iconName;
				}
			}
			$size = real_file_size($path_filename);
		}
        $mtime = filemtime($path_filename);
		$file = new a_file($file_name, $filetype, $size, $mtime, $icon, $path, $perms, $owner, $group);

		$file->set_show_delete($show_delete);
		$this->files[] = $file;
	}

	function read_dir($path, DatabaseConnection $db, $may_delete=FALSE, $search = '')
	{
		global $hiddenfiles, $prefs, $LN;
		$dir = @opendir($path);
		if ($dir === FALSE)
			fatal_error($LN['error_dirnotfound'] . htmlentities(" ($path)"));
		$cnt = 0;
		$this->path = $path;
		$show_delete = ($path != get_dlpath($db)) && $may_delete ;

		while (FALSE !== ($entry = readdir($dir))) {
			if ($entry == '.' || $entry == '..')
				continue;
			if (match_files($entry, $hiddenfiles)) 
				continue;
			if ($search != '' && fnmatch("*$search*", $entry, FNM_CASEFOLD) === FALSE)
				continue;
			$cnt++; 
			$this->add_file($path, $entry, $show_delete);

		}
		closedir($dir);
		$this->total = $cnt;
	}
	private function sort_owner($a, $b)
	{
		if ($a->type == 'dir' && $b->type == 'dir') return $this->dir * strnatcasecmp($a->owner, $b->owner);
		elseif ($a->type == 'dir') return -1;
		elseif ($b->type == 'dir') return 1;
		else return $this->dir * strnatcasecmp($a->owner, $b->owner);
	}
	private function sort_group($a, $b)
	{
		if ($a->type == 'dir' && $b->type == 'dir') return $this->dir * strnatcasecmp($a->group, $b->group);
		elseif ($a->type == 'dir') return -1;
		elseif ($b->type == 'dir') return 1;
		else return $this->dir * strnatcasecmp($a->group, $b->group);
	}
	private function sort_name($a, $b)
	{
		if ($a->type == 'dir' && $b->type == 'dir') return $this->dir * strnatcasecmp($a->name, $b->name);
		elseif ($a->type == 'dir') return -1;
		elseif ($b->type == 'dir') return 1;
		else return $this->dir * strnatcasecmp($a->name, $b->name);
	}
	private function cmp ($a, $b)
	{
		if ($a == $b) return 0;
		else return $this->dir * ($a < $b ? -1 : 1) ;
	}
	private function sort_size($a, $b)
	{
		if ($a->type == 'dir' && $b->type == 'dir') return $this->cmp($a->size, $b->size);
		elseif ($a->type == 'dir') return -1;
		elseif ($b->type == 'dir') return 1;
		else return $this->cmp($a->size, $b->size);
	}

	private function sort_mtime($a, $b)
	{
		if ($a->type == 'dir' && $b->type == 'dir') return $this->cmp($a->mtime, $b->mtime);
		elseif ($a->type == 'dir') return -1;
		elseif ($b->type == 'dir') return 1;
		else return $this->cmp($a->mtime, $b->mtime);
	}
	private function sort_perms($a, $b)
	{
		if ($a->type == 'dir' && $b->type == 'dir') return $this->cmp($a->perms_num, $b->perms_num);
		elseif ($a->type == 'dir') return -1;
		elseif ($b->type == 'dir') return 1;
		else return $this->cmp($a->perms_num, $b->perms_num);
	}
	private function sort_type($a, $b)
	{
		if ($a->type == 'dir' && $b->type == 'dir') return $this->cmp($a->type, $b->type);
		elseif ($a->type == 'dir') return -1;
		elseif ($b->type == 'dir') return 1;
		else return $this->dir * strnatcasecmp($a->type, $b->type);
	}
	function get_files ($sort_key, $start, $count=NULL, $sort_dir = 1)
	{
		if ($sort_dir == -1)
			$this->dir = -1;
		else 
			$this->dir = 1;
		switch($sort_key) {
		default:
		case 'default':
		case 'owner':
			usort($this->files, array($this, 'sort_owner'));
			break;
		case 'group':
			usort($this->files, array($this, 'sort_group'));
			break;
		case 'perms':
			usort($this->files, array($this, 'sort_perms'));
			break;
		case 'name':
			usort($this->files, array($this, 'sort_name'));
			break;
		case 'size':
			usort($this->files, array($this, 'sort_size'));
			break;
		case 'mtime':
			usort($this->files, array($this, 'sort_mtime'));
			break;
		case 'type':
			usort($this->files, array($this, 'sort_type'));
		}
		$up_dir = new a_file ('..', 'dir', '', '', 'folder', $this->path, NULL, NULL, NULL);

		return array_merge (array ($up_dir), array_slice($this->files, $start, $count));
	}
}


$cmd = trim(isset($_REQUEST['cmd'])?$_REQUEST['cmd']:'');
$dir = urldecode(isset($_REQUEST['dir'])?$_REQUEST['dir']:'');


try {
	$dirname = normalise_dir($db, $dir, $username, $is_admin);
} catch (exception $e) {
	die_html($LN['error_nodlpath'], 'admin_config.php', $LN['error_setithere']);
}

$search = get_request('search', '');
$submitbutton = get_request('submitbutton', '');
$offset = get_request('offset', 0);
if ($submitbutton != '') // reset the page skipper if the search button is pressed
	$offset = 0;
$sort = get_request('sort', 'name');
$sort_dir = get_request('sort_dir', 'asc');
$size = get_maxperpage($db,$userID);
$rename_file = NULL;
if ($sort == '') { 
    if (isset($_SESSION['viewfiles']['sort'])) 
        $sort = $_SESSION['viewfiles']['sort'];
    else 
        $sort = 'name';
}
if ($sort_dir == '') {
    if (isset($_SESSION['viewfiles']['sort_dir'])) 
        $sort_dir = $_SESSION['viewfiles']['sort_dir'];
    else 
        $sort_dir = 'asc';
}

$_SESSION['viewfiles']['sort'] = $sort;
$_SESSION['viewfiles']['sort_dir'] = $sort_dir;
$currentdir = $dirname;

switch (strtolower($cmd)) {
case 'delete_file':
	if (!$is_admin)
		die_html($LN['error_filenotallowed']);
	verify_challenge_text($_POST['challenge']);
	//delete a single file
	$file = $_POST['filename'];
	if (strpos($file, '/') === FALSE) 
		$rv = @unlink($dirname . $file);
	else 
		$rv = FALSE;
	if ($rv === FALSE)
		die_html($LN['viewfiles_filenotpermitted']);
	break;
case 'delete_dir':
	if (!$is_admin)
		die_html($LN['error_filenotallowed']);
	verify_challenge_text($_POST['challenge']);
	// recursively delete files and dirs
	$subdir = $_POST['filename'];
	$rv = TRUE;
	$error = '';
	if (strpos($subdir, '/') === FALSE && strstr($subdir, '..') === FALSE) { 
		list ($count, $error) = rmdirtree($dirname . $subdir, 0, TRUE);
		if ($error == '')
			$rv = TRUE;
	} else 
		$rv = FALSE;
	if ($rv === FALSE)
		die_html($LN['viewfiles_filenotpermitted']);
	if ($error != '')
		die_html($error);
	break;
case 'zip_dir': // not very neat now....
	$tar_cmd = my_escapeshellcmd (get_config($db,'tar_path'));
	if ($rprefs['webdownload'] != 1)
		fatal_error($LN['error_filenotallowed']);
	verify_challenge_text($_GET['challenge']);
	$tar_cmd = my_escapeshellcmd (get_config($db,'tar_path'));
	if ($tar_cmd != 'off' && $tar_cmd != '') {
		$subdir = $_GET['filename'];
		if (strpos($subdir, '/') === FALSE && strstr($subdir, '..') === FALSE) {
			$subdir_dl = preg_replace ('/[^a-z0-9_\-.]+/i', '_', $subdir);
			header('Content-type: application/x-gtar');
			header('Content-Description: URD Generated Data');
			header("Content-Disposition: attachment; filename=\"$subdir_dl.tgz\"");

			$path = my_escapeshellarg ($dirname);
			$filename = my_escapeshellarg($subdir);
			set_time_limit(3600);
			ob_end_flush(); // turn off output buffering otherwise large files will be hit by the memory limit
			$pipe = popen("$tar_cmd -cz -C $path $filename 2>> /tmp/tar", 'r');
			if ($pipe === FALSE)
				fatal_error($LN['viewfiles_compressfailed']);
			$size = 0;
			while (!feof($pipe)) {
				$output = fread($pipe, 10240);
				if ($output === FALSE)
					fatal_error($LN['error_filereaderror']);
				else {
					$size += count($output);
					echo $output;
				}
			}
			pclose($pipe);
			add_stat_data($db, STAT_ACTION_WEBVIEW, $size, $userID);
			die; 
		} else 
			die_html( $LN['viewfiles_filenotpermitted']);
	} else
		fatal_error($LN['viewfiles_tarnotset']);
	die;
	break;
case 'show_files':
	$files = new file_list;
	$files->read_dir($currentdir, $db, $is_admin, $search);

	$dir = (strtolower($sort_dir) == 'desc')? -1: 1;
	$info = build_skipper($db, $files->total, $userID, $currentdir, $offset, $size);
	$pages = $info[0];
	$currentpage = $info[1];
	$lastpage = $info[2];

	$challenge = set_challenge();
	$tar_cmd = my_escapeshellcmd(get_config($db,'tar_path'));
	$use_tar = (int)(($tar_cmd != 'off' && $tar_cmd != '') && ($rprefs['webdownload'] == 1));

	$smarty->assign('search',		$search);
	$smarty->assign('pages',		$pages);
	$smarty->assign('use_tar',		$use_tar);
	$smarty->assign('currentpage',	$currentpage);
	$smarty->assign('lastpage',		$lastpage);
	$smarty->assign('sort',			$sort);
	$smarty->assign('sort_dir', 	$sort_dir);
	$smarty->assign('offset', 		$offset);
	$smarty->assign('directory',	$currentdir);
	$smarty->assign('files',		$files->get_files($sort, $offset, $size, $dir));
	$smarty->assign('challenge',	$challenge);
	$smarty->assign('maxstrlen',	$prefs['maxsetname']);

	$smarty->display('ajax_showviewfiles.tpl');

	die;
	break;
case 'show_rename':
	if (!isset($_POST['filename']))
		die_html('No filename given XXX'); // XXX
	$filename = $_POST['filename'];
	$fullname = $dirname.$filename;
	$rights = substr(sprintf('%o', fileperms($fullname)), -4);
	$challenge = set_challenge();
	$group = posix_getgrgid(filegroup($fullname));
	$group = $group['name'];
	$groups_orig = read_system_groups();
	sort($groups_orig);
	foreach ($groups_orig as $g) {
		$groups["$g"] = $g;
	}

	$smarty->assign('challenge',		$challenge);
	$smarty->assign('textboxsize',		TEXT_BOX_SIZE);
	$smarty->assign('directory',		$currentdir);
	$smarty->assign('maxstrlen',		((int)$prefs['maxsetname'])/3);
	$smarty->assign('filename',		$filename);
	$smarty->assign('rights', 		$rights);
	$smarty->assign('group', 		$group);
	$smarty->assign('groups', 		$groups);
	$smarty->display('ajax_editviewfiles.tpl');

	die;
	break;
case 'do_rename':
	verify_challenge_text($_POST['challenge']);
	$name = $_POST['oldfilename'];
	$newname = $_POST['newfilename'];
	$rights = $_POST['rights'];
	$group = $_POST['group'];
	if ($name != $newname) {
		if ($name == '' || $newname == '')
			die_html($LN['error_needfilenames']);
		if (strpos($name, '/') !== FALSE || strpos($newname, '/') !== FALSE)
			die_html($LN['error_illegalfilename']);

		clearstatcache();
		if (file_exists($dirname.$newname))
			die_html($LN['error_fileexists']);
		$rv = @rename($dirname . $name, $dirname . $newname);
		if ($rv === FALSE)
			die_html($LN['error_cannotrename']);
	}
	$fullname = $dirname.$newname;
	$currights = substr(sprintf('%o', fileperms($fullname)), -4);
	if ($currights != $rights || $rights == '') {
		$rv = @chmod ($fullname, $rights);
		if ($rv === FALSE)
			die_html($LN['error_cannotchmod']);
	}
	$curgroup = posix_getgrgid(filegroup($fullname));
	$curgroup = $curgroup['name'];
	if($group != $curgroup || $group == '') {
		$rv = @chgrp($fullname, $group);
		if ($rv === FALSE)
			die_html($LN['error_cannotchgrp']);
	}

	
	break;
case 'up_nzb':
	verify_challenge_text($_POST['challenge']);
	try {
		$rprefs = load_config($db);
		$uc = new urdd_client($rprefs['urdd_host'],$rprefs['urdd_port'],$userID);
		$uc->parse_nzb($_POST['dir'] . $_POST['filename']);
	} catch (exception $e) {
		die_html($e->getMessage());
	}
	die_html ($LN['uploaded'] . ' ' . htmlentities($_POST['dir'] . $_POST['filename']));
	break;
default:
	die_html("O-oh - Unknown command $cmd");
	break;
}

die_html('OK');

			
?>
